<?php
namespace app\common\model;
use think\Model;
use EasyWeChat\Factory;
use think\facade\Request;
use think\facade\Db;
use think\facade\Cache;
use think\facade\Session;
use think\facade\Config;
use think\model\concern\SoftDelete;
use app\common\model\Wechat;

class WechatUser extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;
    protected $autoWriteTimestamp = true;
    
    public static function get_lists()
    {
        $list = self::where('subscribe',1)->select();
        return $list;
    }
    
    static function update_userinfo($user,$shop_id) {
        $info = self::where('openid',$user['openid'])->find();
        if(!$info){
            $user['shop_id'] = $shop_id;
            $user['gender'] = $user['sex'];
            $user['type'] = 'weixin';
            $user['avatarurl'] = $user['headimgurl'];
            $result = self::create($user);
            $info = self::where('openid',$user['openid'])->find();
        }
        return $info;
    }
    
    
    
}